<?php
namespace Stats\Controller;
use Todo\Controller\StatsController;
use Todo\Util\ArrayUtil;

/**
 * Class UserController 用户查询统计
 * @package Stats\Controller
 */
class UserController extends StatsController {

    protected $_format = 'depart,identity';

    protected $_header = array(
        array('account', '账号'),
        array('nickname', '昵称'),
        array('phone', '手机'),
        array('email', '邮箱'),
        array('depart_text', '部门'),
        array('identity_text', '身份'),
    );

    /**
     * 报表
     */
    public function index(){
        $this->_loadModel();
        $list = $this->_model->where(array('is_del'=>0))->group('depart_id')->field('depart_id, count(id) total')->select();
        foreach ($list as &$row) $this->_model->format($row, 'depart');
        $xdata = ArrayUtil::getColumn($list, 'depart_text');
        $series = ArrayUtil::getColumn($list, 'total');
        $this->assign('xdata', $xdata);
        $this->assign('series', $series);
        $this->display();
    }

    protected function _filter(&$where){
        $where['is_del'] = 0;
        $keyword = I('get.keyword/s');
        if($keyword) $where['_string'] = "account like '%" . $keyword . "%' OR nickname like '%" . $keyword . "%'";
    }

    protected function _loadModel(){
        if(!$this->_model) $this->_model = D('Todo/Sys/User');
    }
}